import { useState } from "react";
import { makeFacade, RoomFacade } from "@/facade/roomFacade";
import { File, LiveStream } from "@/models/LiveRoom";
import { useObservable } from '@/utils/rxHelpers';

type RoomUiHookTuple = [
  RoomFacade,
  string,
  string,
  string,
  string,
  string,
  string,
  string,
  string,
  string,
  string,
  string,
  string,
  number,
  File[],
  string,
  Date,
  Date,
  number,
  number,
  number,
  number,
  string,
  string,
  boolean,
  boolean,
  LiveStream[],
  string,
  number,
  boolean,
  boolean,
  number,
];

//需要在页面用到的变量都在这里hook，主要用于简化页面调用逻辑和代码
export function useRoomUiFacade(): RoomUiHookTuple {
  const [roomFacade] = useState(() => makeFacade());
  const [roomName] = useObservable(roomFacade.roomName$, "");
  const [anchorId] = useObservable(roomFacade.anchorId$, "");
  const [anchorName] = useObservable(roomFacade.anchorName$, "");
  const [ownerName] = useObservable(roomFacade.ownerName$, "");
  const [ownerId] = useObservable(roomFacade.ownerId$, "");
  const [ownerLogo] = useObservable(roomFacade.ownerLogo$, "");
  const [anchorLogo] = useObservable(roomFacade.anchorLogo$, "");
  const [orgId] = useObservable(roomFacade.orgId$, "");
  const [roomRole] = useObservable(roomFacade.roomRole$, "");
  const [orgName] = useObservable(roomFacade.orgName$, "");
  const [orgLogo] = useObservable(roomFacade.orgLogo$, "");
  const [tip] = useObservable(roomFacade.tips$, "");
  const [roomStatus] = useObservable(roomFacade.status$, 0);
  const [files] = useObservable(roomFacade.files$, []);
  const [description] = useObservable(roomFacade.description$, "");
  const [startTime] = useObservable(roomFacade.startTime$, new Date());

  const [endTime] = useObservable(roomFacade.endTime$, new Date());

  const [duration] = useObservable(roomFacade.duration$, 0);
  const [visits] = useObservable(roomFacade.visits$, 0);
  const [shares] = useObservable(roomFacade.shares$, 0);
  const [likes] = useObservable(roomFacade.likes$, 0);
  const [passwd] = useObservable(roomFacade.passwd$, "");
  const [picUrl] = useObservable(roomFacade.picUrl$, "");
  const [forceSign] = useObservable(roomFacade.forceSignIn$, false);
  const [allowShare] = useObservable(roomFacade.allowShare$, true);
  const [liveStreams] = useObservable(roomFacade.liveStreams$, []);
  const [preLoadVideo] = useObservable(roomFacade.preLoadVideo$, "");
  const [ui_progress] = useObservable(roomFacade.videoProgress$, 0)
  const [ui_videoEnded] = useObservable(roomFacade.videoEnded$, false)

  const [audioStatus] = useObservable(roomFacade.audioStatus$, false)
  const [audienceToast] = useObservable(roomFacade.audienceToast$, 0)

  //实在长得让人无力吐槽
  return [
    roomFacade,
    roomName,
    anchorId,
    anchorName,
    ownerName,
    ownerId,
    ownerLogo,
    anchorLogo,
    orgId,
    roomRole,
    orgName,
    orgLogo,
    tip,
    roomStatus,
    files,
    description,
    startTime,
    endTime,
    duration,
    visits,
    shares,
    likes,
    passwd,
    picUrl,
    forceSign,
    allowShare,
    liveStreams,
    preLoadVideo,
    ui_progress,
    ui_videoEnded,
    audioStatus,
    audienceToast
  ];
}
